package com.liuguang.gateway.config.interceptor;

import com.alibaba.fastjson.JSONObject;
import com.liuguang.gateway.controller.BusinessController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: LoginInterceptor
 * @Description：登录拦截器，比较两次登录的ip地址，当出现不一致的时候，也会登录成功，但是使用邮件通知用户，可能存在被盗号的风险
 * 使用切面也可以的。
 * 这个功能的验证就不应该在这，应该在验证成功后
 * @Author: wanghr
 * Date: 4:59 PM 2020/10/12
 * Version: 1.0
 */
//@Component
public class LoginInterceptor implements HandlerInterceptor {
    private static final Logger logger = LoggerFactory.getLogger(LoginInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        logger.info("进入LoginInterceptor");
        // todo：1、常用的Ip，默认是注册的ip
        //在数据库查询账号的常用ip？请求能到这说明，应该再验证成功后进行而不是拦截器

        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        logger.info("执行LoginInterceptor.afterCompletion方法");
    }
}
